package com.heima.api.fallback;

import com.heima.api.ItemClient;
import com.heima.dto.ItemDTO;
import com.heima.dto.OrderDetailDTO;
import com.heima.dto.PageItemDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@Slf4j
public class ItemClientFallbackFactory implements FallbackFactory<ItemClient> {

    // cause 远程服务的异常信息
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {


            @Override
            public PageItemDto queryPages(Integer page) {
                return null;
            }

            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.error("cart->item->:根据Id查询商品详情信息(第二种方式)");
                return Collections.emptyList();
            }

            @Override
            public void deductStock(List<OrderDetailDTO> items) {
                throw new RuntimeException("远程调用失败！");
            }
        };
    }
}
